import React from 'react';
import { Redirect } from 'react-router-dom';
import UserLayout from './userLayout';
import BasicLayout from './basicLayout';
import router from 'umi/router';
import { LocaleProvider } from 'antd';
import zh_CN from 'antd/lib/locale-provider/zh_CN';

export default class extends React.PureComponent {
	constructor() {
		super();
		this.state = {};
	}
	getLayout = pathname => {
		if (/\/user\/[login|signup]/.test(pathname)) {
			return <UserLayout>{this.props.children}</UserLayout>;
		} else if (/^\/[data|graphic]/.test(pathname)) {
			return <BasicLayout>{this.props.children}</BasicLayout>;
		} else {
			return <>{this.props.children}</>;
		}
	};
	render() {
		const pathname = window.location.pathname;
		if (pathname === '/') {
			return <Redirect to="/user/login" />;
		}
		return <LocaleProvider locale={zh_CN}>{this.getLayout(pathname)}</LocaleProvider>;
	}
}
